#include<iostream>
using namespace std;
#include<set>
#include<string>

int lengthOfLongestSubstring(string s) {
    int length = s.size();
    int left = 0;
    int right = 0;
    int nums = 0;
    set<char> example;
    while (right <=length)
    {
        while (right < length)
        {
            if ((example.insert(s[right])).second)
            {
                right++;
            }
            else {
                break;
            }

        }
        if (nums == 0)
        {
            nums = example.size();
        }
        else
        {
            if (example.size() > nums)
            {
                nums = example.size();
            }
        }
        while (left < length)
        {
            if (!(example.insert(s[right])).second)
            {
                example.erase(s[left]);
                left++;
            }
            else {
                break;
            }

        }
        right++;
    }

    return nums;
}
int main()
{
    string str = "abcabcbb";
    lengthOfLongestSubstring(str);
	return 0;
}